<?php

namespace app\admin\controller;

use core\Controller;
use core\Request;
use core\Session;
use think\facade\Db;

class Base extends Controller
{
    protected $request;
    protected $sysConfig;

    public function _before_action()
    {
        $isLogin = Session::has('username');
        if($isLogin==false){
            redirect('/admin/login/index');
        }

        $this->request = Request::instance();

        //赋值当前菜单
        if (method_exists($this, '_infoModule')) {
            $this->assign('infoModule', $this->_infoModule());
        }

        $this->getUserInfo();

        $this->getConfig();
    }

    //获取系统配置
    public function getConfig()
    {
        $infoConfig = model('Config')->getInfo();
        if($infoConfig['switchVersion']==1){
            $infoConfig['systemTitle'] = '框架版';
        }else{
            $infoConfig['systemTitle'] = '单页版';
        }
        $this->sysConfig = $infoConfig;
        $this->assign('infoConfig', $infoConfig);
    }

    //登录信息
    public function getUserInfo()
    {
        $username = session('username');
        $loginUserInfo = model('Admin')->getWhereInfo(['username'=>$username]);
        $this->assign('loginUserInfo', $loginUserInfo);
    }

}
